package com.ibp.controller;

import com.ibp.entity.ServiceNode;
import com.ibp.entity.SysRunManage;
import com.ibp.form.CmdForm;
import com.ibp.response.DataResponse;
import com.ibp.service.ExecuteCmdService;
import com.ibp.service.LogNodeService;
import com.ibp.service.ServiceNodeService;
import com.ibp.service.SysRunManageService;

import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping({"sysRunManage"})
public class SysRunManageController extends BasicController{
	private static Logger logger = LoggerFactory.getLogger(SysRunManageController.class);

	@Autowired
	SysRunManageService sysRunManageSerivceImpl;
	@Autowired
	ServiceNodeService serviceNodeServiceImpl;
	@Autowired
	LogNodeService logNodeServiceImpl;
	@Autowired
	ExecuteCmdService executeCmdServiceImpl;
  
  /***
   * 
   * 进入系统运管理页面
   * @return
   */
  @RequestMapping({"/sysRunManageList"})
  public String toSysRunManageList()
  {
    logger.info("进入系统运管理页面sys_run_manage_list.jsp");
    return "ibp/sys_run_manage_list";
  }

  /**
   * 进入注册中心页面
   * @return
   */
  @RequestMapping({"/registryList"})
  public String toRegistryList()
  {
    logger.info("进入注册中心页面registry_list.jsp");
    return "ibp/registry_list";
  }

  /**
   * 进入服务节点页面页面
   * @return
   */
  @RequestMapping({"/serviceNodeList"})
  public String toServiceNodeList()
  {
    logger.info("进入服务节点页面页面service_node_list.jsp");
    return "ibp/service_node_list";
  }

  /**
   * 进入日志归集节点页面
   * @return
   */
  @RequestMapping({"/logNodeDetail"})
  public String toSysRunMan()
  {
    logger.info("进入日志归集节点页面log_node_detail.jsp");
    return "ibp/log_node_detail";
  }

  /**
   * 查询系统运管理列表
   * @param srm
   * @return
   */
  @RequestMapping({"/getIbmsInfo"})
  @ResponseBody
  public DataResponse<Map> getIbmsInfo(String cmd)
  {
    logger.info("查询注册中心状态" + cmd);
    DataResponse<Map> response = new DataResponse<Map>();
    response.setData(this.sysRunManageSerivceImpl.getIbmsInfo(cmd));
    return response;
  }
  
  
  
  
  /**
   * 查询系统运管理列表
   * @param srm
   * @return
   */
  @RequestMapping({"/getSysRunManageList"})
  @ResponseBody
  public DataResponse<Map> getSysRunManageList(SysRunManage srm)
  {
    logger.info("查询系统运管理列表" + srm.toString());
    DataResponse<Map> response = new DataResponse<Map>();
    response.setData(this.sysRunManageSerivceImpl.getSysRunManage(srm));
    return response;
  }

  /**
   * 查询注册中心会话列表
   * @param srm
   * @return
   */
  @RequestMapping({"/getRegistryList"})
  @ResponseBody
  public DataResponse<Map> getRegistryList(SysRunManage srm)
  {
    logger.info("查询注册中心会话列表" + srm.toString());
    DataResponse<Map> response = new DataResponse<Map>();
    response.setData(this.sysRunManageSerivceImpl.getRegistryList(srm));
    return response;
  }

  /**
   * 服务结节查询
   * @param sn
   * @return
   */
  @RequestMapping({"/getServiceNodes"})
  @ResponseBody
  public DataResponse<List<ServiceNode>> getServiceNodes(ServiceNode sn)
  {
    logger.info("服务结节查询" + sn.toString());
    DataResponse<List<ServiceNode>> response = new DataResponse<List<ServiceNode>>();
    response.setData(this.serviceNodeServiceImpl.getServiceNodes(sn));
    return response;
  }
  
  /***
   * 返回日志归集节点状态
   * @return
   */
  @RequestMapping("/getLogNode")
  @ResponseBody
  public DataResponse<Map> getLogNode(String cmd){
	  logger.info("获取日志归集节点状态");
	  DataResponse<Map> response = new DataResponse<Map>();
	  response.setData(logNodeServiceImpl.getLogNode(cmd));
	  return response ;
  }
  
  /***
   * 执行ibmsCmd命令，返回响应结果
   * @param cmd
   * @return
   */
  @RequestMapping("/executeIbmsCmdData")
  @ResponseBody
  public DataResponse<String> executeIbmsCmdData(String cmd){
	  logger.info("执行cmd命令:----->"+cmd);
	  DataResponse<String> response = new DataResponse<String>();
	  response.setData(executeCmdServiceImpl.executeIbmsCmdData(cmd));
	  return response ;
  }

  
  /***
   * 执行ibmsCmd命令，返回响应结果
   * @param cmd
   * @return
   */
  @RequestMapping("/executeIbmsCmd")
  @ResponseBody
  public DataResponse<String> executeIbmsCmd(String cmd){
	  logger.info("执行cmd命令:----->"+cmd);
	  DataResponse<String> response = new DataResponse<String>();
	  response.setData(String.valueOf(executeCmdServiceImpl.executeIbmsCmd(cmd)));
	  return response ;
  }
  
  /***
   * 执行iblogCmd命令,返回响应结果
   * @param cmd
   * @return
   */
  @RequestMapping("/executeIblogCmd")
  @ResponseBody
  public DataResponse<String> executeIblogCmdData(String cmd){
	  logger.info("执行cmd命令:----->"+cmd);
	  DataResponse<String> response = new DataResponse<String>();
	  response.setData(executeCmdServiceImpl.executeIblogCmdData(cmd));
	  return response ;
  }
  
  
  /***
   * 执行Ibcmd命令,返回命令状态
   * @param ip
   * @param port
   * @param cmd
   * @return
   */
  @RequestMapping("/executeIbcmd")
  @ResponseBody
  public DataResponse<String> executeIbcmd(CmdForm cmdForm){
	  logger.info("执行Ibcmd命令：------>"+cmdForm.toString());
	  DataResponse<String> response = new DataResponse<String>();
	  response.setData(String.valueOf(executeCmdServiceImpl.executeIbcmd(cmdForm)));
	  return response ;
  }
  
  
  
}